package TestThreadPool;

import org.junit.jupiter.api.Test;

import java.util.concurrent.*;

public class TestThreadPoolBegin {

    public static void main(String[] args) throws Exception {
        ExecutorService es = Executors.newSingleThreadExecutor();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("Runnable线程处理开始...");
                int a = 0;
                int b = 3;
                System.out.println("除以0的结果为：" + b / a);
                System.out.println("Runnable线程处理结束...");
            }
        };
//        es.execute(runnable);
        es.submit(runnable);
        es.shutdown();
    }

    @Test
    public void test2() throws Exception {
        ExecutorService es = Executors.newSingleThreadExecutor();
        Callable callable = new Callable() {
            @Override
            public Object call() throws Exception {
                System.out.println("线程处理开始...");
                int a = 0;
                int b = 3;
                System.out.println("除以0的结果为：" + b / a);
                System.out.println("线程处理结束...");
                return "0";
            }
        };
        Future<String> future = es.submit(callable);
        System.out.println("任务执行完成，结果为：" + future.get());
    }
}